<?php

namespace App\Http\Controllers;

use App\Http\Service\SearchhistoryService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Config;

class SearchhistoryController extends BaseController
{
    public $URL_MAP;
    private $getRules=[
            'keyword'=> 'required',
            'people_id'=> 'required',
            'type'=> 'required',
        ];
    private  $getRulesMessage=[
            'keyword.required'=> '关键字【keyword】不能为空',
            'people_id.required'=> '用户id【people_id】不能为空',
            'type.required'=> '类型【type】不能为空',
        ];
    public $repository;
    public function __construct(SearchhistoryService $repository)
    {

        parent::__construct();
        $this->repository = $repository;

    }

    //搜索框历史记录列表
    public function getList(Request $request)
    {
        $data=[
            'people_id'=>$request->json("people_id"),
            'type'=>$request->json("type"),
        ];
        $this->success($this->repository->getList($request,$data));
        
    }
    //搜索框历史记录添加
    public function addDate(Request $request)
    {
        $data=[
            'people_id'=>$request->json("people_id"),
            'keyword'=>$request->json("keyword"),
            'type'=>$request->json("type"),
        ];
        $this->checkrule($data,$this->getRules,$this->getRulesMessage);
        $this->success($this->repository->addDate($request,$data));
        
    }
    //搜索框历史记录删除
    public function del(Request $request)
    {
        $ids=$request->json("id");
        $data=[
            'people_id'=>$request->json("people_id"),
            'type'=>$request->json("type"),
            'id'=>$ids,
        ];

        if(empty($ids)){
            $this->error('参数错误');
        }
        $this->repository->del($request,$data,$ids);
        
    }
    

  

}
